#!/usr/bin/env node
//告诉操作系统，我执行自定义命令的时候，帮我使用node去执行这个文件
import {program} from 'commander'
import fs from 'node:fs'
import inquirer from 'inquirer'
import {checkPath, downloadTemp} from "./utils.js";

let json = fs.readFileSync('./package.json')
json = JSON.parse(json)

program.version(json.version)
program.command('create <projectName>').alias('c').description('创建项目').action((projectName) => {
    inquirer.prompt([{
        type: 'input', //input输入，confirm确认框，list选择框，checkbox
        name: 'projectName',  //返回值的key
        message: '请输入项目名称',  //描述
        default: projectName   //默认值
    }, {
        type: 'confirm',
        name: 'isTS',
        message: '是否选用TypeScript模板'
    }]).then(res=>{
        if(checkPath(res.projectName)){
            console.log('文件夹已存在')
        }

        if(res.isTs){
           downloadTemp('ts', res.projectName)
        } else {
            downloadTemp('js', res.projectName)
        }
    })
})

program.parse(process.argv)